﻿using System;
using System.IO;
using System.Net;
using ClientDomain.Commnads;
using ClientDomain.Properties;
using Comunication;

namespace ClientDomain
{
    public static class ClientAccessComunication
    {
        public static string FileName;
        //public static string FileNameDownload;

        public static void EstablecerComunicacion()
        {
            IPAddress ipAddress = IPAddress.Parse(Settings.Default.MulticastAddress);
            IUdpPacketProcessor package = new UdpClientPackage();

            UDPClient.BeginReceiveUDP(Convert.ToInt32(Settings.Default.MulticastPort), ipAddress, package);

        }

        // ReSharper disable UnusedMember.Local
        public static bool SubirArchivo(string fileName)
        {
            FileName = fileName;
            IPAddress ipAddress = IPAddress.Parse(Settings.Default.MulticastAddress);
            IPEndPoint remoteep = new IPEndPoint(ipAddress, Convert.ToInt32(Settings.Default.MulticastPort));
            UploadFindServer findServer = new UploadFindServer();
            return UDPClient.SendUdpMessage(remoteep, findServer);
        }
        // ReSharper restore UnusedMember.Local

        public static bool BajarArchivo(string fileName)
        {
            FileName = fileName;
            IPAddress ipAddress = IPAddress.Parse(Settings.Default.MulticastAddress);
            IPEndPoint remoteep = new IPEndPoint(ipAddress, Convert.ToInt32(Settings.Default.MulticastPort));
            DownloadFindServer downloadFindServer = new DownloadFindServer(FileName , 0);
            return UDPClient.SendUdpMessage(remoteep, downloadFindServer);
        }

        public static void InicializarCarpeta()
        {
            if (!Directory.Exists(Settings.Default.FolderPath))
            {
                Directory.CreateDirectory(Settings.Default.FolderPath);
            }
        }
    }
}
